/**
 * @author Fang Lu, fanglupku@gmail.com
 * 2011-5-22
 */
package com.autotag;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;

import com.autotag.nlp.WordStemmer;

public class WSDLStopWord {
	private static HashSet<String> stopWordSet;
	static {
		initStopWordSet("models/wsdl-stop-words.txt");
	}
	public static void main(String args[]){
		System.out.println(isStopWord("this"));
	}
	public static boolean isStopWord(String thisWord){
		String stem = WordStemmer.getStem(thisWord.toLowerCase());
		if (stopWordSet.contains(stem)){
			return true;
		}
		return false;
	}
	public static void initStopWordSet(String filename){
		stopWordSet = new HashSet<String>();
		File file = new File(filename);
		try {
			FileReader fr = new FileReader(file);
			BufferedReader br = new BufferedReader(fr);
			
			String oneLine = br.readLine();
			while (oneLine != null){
				oneLine = oneLine.trim();
				
				if (oneLine.length() > 0){
					stopWordSet.add(WordStemmer.getStem(oneLine));
				}
				
				oneLine = br.readLine();
			}
			
			br.close();
			fr.close();
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
